﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.UI.WebControls;
using Medianamik.Core;

namespace Medianamik.UI.Controls
{
    public class NodeTypeIcon : Image
    {
        protected override void OnPreRender(EventArgs e)
        {
            if (string.IsNullOrEmpty(CssClass))
            {
                CssClass = "IconesElements";
            }
            base.OnPreRender(e);
        }

        public Guid NodeTypeId
        {
            get
            {
                return ViewState["NodeTypeId"] as Guid?
                       ?? Guid.Empty;
            }
            set
            {
                ViewState["NodeTypeId"] = value;
            }
        }

        private NodeType _nodeType;
        protected NodeType NodeType
        {
            get
            {
                return _nodeType ?? (_nodeType = NodeTypeManager.GetNodeType(NodeTypeId));
            }
        }

        public override string AlternateText
        {
            get
            {
                return String.Format("{0} ({1})",
                    NodeType.LocalizedName, NodeType.Name);

            }
            set
            {
                ;
            }
        }

        public override string ToolTip
        {
            get
            {
                return String.Format("{0} ({1})",
                    NodeType.LocalizedName, NodeType.Name);
            }
            set
            {
                ;
            }
        }

        protected override void AddAttributesToRender(System.Web.UI.HtmlTextWriter writer)
        {
            writer.AddAttribute("title", String.Format("{0} ({1})",
                    NodeType.LocalizedName, NodeType.Name));
            base.AddAttributesToRender(writer);
        }

        public override bool Visible
        {
            get
            {
                return NodeType != null && !string.IsNullOrEmpty(NodeType.IconPath);
            }
            set
            {
                ;
            }

        }
        public override string ImageUrl
        {
            get
            {
                return NodeType.IconPath;               
            }
            set
            {
                ;
            }
        }
        
    }

}

